
http://www.cplusplus.com/doc/tutorial/
TUTORIAL

  Please read this! It is not just for show!

Comments
Comments are pieces of source code discarded from the code by the compiler. 
They do nothing. Their purpose is only to allow the programmer to insert notes 
or descriptions embedded within the source code.

C++ supports two ways to insert comments:

    // line comment
    /* block comment */
	

int= integer


Identifiers
A valid identifier is a sequence of one or more letters, digits or underline symbols 
( _ ). The length of an identifier is not limited, although for some compilers only 
the 32 first characters of an identifier are significant (the rest are not considered).

Neither spaces nor marked letters can be part of an identifier. Only letters, digits 
and underline characters are valid. In addition, variable identifiers should always 
begin with a letter. They can also begin with an underline character ( _ ), but this 
is usually reserved for external links. In no case they can begin with a digit.

Another rule that you have to consider when inventing your own identifiers is that 
they cannot match any key word of the C++ language nor your compiler's specific ones
 since they could be confused with these. For example, the following expressions are
 always considered key words according to the ANSI-C++ standard and therefore they 
 must not be used as identifiers:

    asm, auto, bool, break, case, catch, char, class, const, const_cast, continue, 
	default, delete, do, double, dynamic_cast, else, enum, explicit, extern, false,
	float, for, friend, goto, if, inline, int, long, mutable, namespace, new, 
	operator, private, protected, public, register, reinterpret_cast, return, short,
	signed, sizeof, static, static_cast, struct, switch, template, this, throw, true,
	try, typedef, typeid, typename, union, unsigned, using, virtual, void, volatile, wchar_t 

Additionally, alternative representations for some operators do not have to be 
used as identifiers since they are reserved words under some circumstances:

    and, and_eq, bitand, bitor, compl, not, not_eq, or, or_eq, xor, xor_eq 

Your compiler may also include some more specific reserved keywords. For example,
 many compilers which generate 16 bit code (like some compilers for DOS) also 
 include far, huge and near as key words.

Very important: The C++ language is "case sensitive", that means that an identifier
 written in capital letters is not equivalent to another one with the same name but 
 written in small letters. Thus, for example the variable RESULT is not the same 
 as the variable result nor the variable Result.


  Declaration of variables
In order to use a variable in C++, we must first declare it specifying which 
of the data types above we want it to be. The syntax to declare a new variable is 
to write the data type specifier that we want (like int, short, float...) followed 
by a valid variable identifier. For example:

    int a;
    float mynumber;

Are valid declarations of variables. The first one declares a variable of type int 
with the identifier a. The second one declares a variable of type float with the 
identifier mynumber. Once declared, variables a and mynumber can be used within the
 rest of their scope in the program.

If you need to declare several variables of the same type and you want to save some 
writing work you can declare all of them in the same line separating the identifiers
with commas. For example:

    int a, b, c;

declares three variables (a, b and c) of type int , and has exactly the same meaning
 as if we had written:

    int a;
    int b;
    int c;

  Initialization of variables
When declaring a local variable, its value is undetermined by default. But you may 
want a variable to store a concrete value the moment that it is declared. In order 
to do that, you have to append an equal sign followed by the value wanted to the 
variable declaration:

    type identifier = initial_value ; 

For example, if we want to declare an int variable called a that contains the 
value 0 at the moment in which it is declared, we could write:

    int a = 0;

Additionally to this way of initializating variables (known as c-like), C++ 
has added a new way to initialize a variable: by enclosing the initial value
 between parenthesis ():

    type identifier (initial_value) ; 

For example:

    int a (0); 

Both ways are valid and equivalent in C++.

  Constants: Literals.
A constant is any expression that has a fixed value. They can be divided in 
Integer Numbers, Floating-Point Numbers, Characters and Strings.

Integer Numbers

    1776
    707
    -273

they are numerical constants that identify integer decimal numbers. Notice that 
to express a numerical constant we do not need to write quotes (") nor any special
 character. There is no doubt that it is a constant: whenever we write 1776 in a 
 program we will be referring to the value 1776.

In addition to decimal numbers (those that all of us already know) C++ allows the 
use as literal constants of octal numbers (base 8) and hexadecimal numbers (base 16).
 If we want to express an octal number we must precede it with a 0 character 
 (zero character). And to express a hexadecimal number we have to precede it 
 with the characters 0x (zero, x). For example, the following literal constants
 are all equivalent to each other:


75         // decimal
0113       // octal
0x4b       // hexadecimal

All of them represent the same number: 75 (seventy five) expressed as a radix-10
 number, octal and hexdecimal, respectively.

  Characters and strings
There also exist non-numerical constants, like:

    'z'
    'p'
    "Hello world"
    "How do you do?" 

The first two expressions represent single characters, and the following two
 represent strings of several characters. Notice that to represent a single character
 we enclose it between single quotes (') and to express a string of more than one 
 character we enclose them between double quotes (").

When writing both single characters and strings of characters in a constant way, 
it is necessary to put the quotation marks to distinguish them from possible 
variable identifiers or reserved words. Notice this:

    x
    'x' 

x refers to variable x, whereas 'x' refers to the character constant 'x'.


Assignation (=).
    The assignation operator serves to assign a value to a variable.

        a = 5;

    assigns the integer value 5 to variable a. The part at the left of the = 
	operator is known as lvalue (left value) and the right one as rvalue (right value). 
	lvalue must always be a variable whereas the right side can be either a constant,
	a variable, the result of an operation or any combination of them.

    It is necessary to emphasize that the assignation operation always takes place 
	from right to left and never at the inverse.

        a = b;

    assigns to variable a (lvalue) the value that contains variable b (rvalue) 
	independently of the value that was stored in a at that moment. Consider also 
	that we are only assigning the value of b to a and that a later change of 
	b would not affect the new value of a.

    For example, if we take this code :

int a, b;    // a:?  b:?
a = 10;      // a:10 b:?
b = 4;       // a:10 b:4
a = b;       // a:4 b:4
b = 7;       // a:4 b:7

    will give us the result that the value contained in a is 4 and the one 
	contained in b is 7. The final modification of b has not affected a, 
	although before we have declared a = b; (right-to-left rule).

    A property that C++ has over other programming languages is that the 
	assignation operation can be used as the rvalue (or part of an rvalue) 
	for another assignation. For example:

        a = 2 + (b = 5);

    is equivalent to:

        b = 5;
        a = 2 + b;

    that means: first assign 5 to variable b and then assign to a the 
	value 2 plus the result of the previous assignation of b (that is 5), 
	leaving a with a final value of 7. Thus, the following expression is also valid in C++:

        a = b = c = 5;

    assigns 5 to the three variables a, b and c.

Arithmetic operators ( +, -, *, /, % )
    The five arithmetical operations supported by the language are:

        +	addition
        -	subtraction
        *	multiplication
        /	division
        %	module

    Operations of addition, subtraction, multiplication and division 
	should not suppose an understanding challenge for you since they 
	literally correspond with their respective mathematical operators.

    The only one that may not be known by you is the module, specified 
	with the percentage sign (%). Module is the operation that gives the remainder 
	of a division of two integer values. For example, if we write a = 11 % 3;, 
	the variable a will contain 2 as the result since 2 is the remainder from 
	dividing 11 between 3.

Compound assignation operators (+=, -=, *=, /=, %=, >>=, <<=, &=, ^=, |=)
    A feature of assignation in C++ that contributes to its fame of sparing 
	language when writing are the compound assignation operators (+=, -=, *= 
	and /= among others), which allow to modify the value of a variable with 
	one of the basic operators:

        value += increase; is equivalent to value = value + increase;
        a -= 5; is equivalent to a = a - 5;
        a /= b; is equivalent to a = a / b;
        price *= units + 1; is equivalent to price = price * (units + 1);

    and the same for all other operations.

Increase and decrease.
    Another example of saving language when writing code are the increase operator 
	(++) and the decrease operator (--). They increase or reduce by 1 the value 
	stored in a variable. They are equivalent to +=1 and to -=1, respectively. Thus:

        a++;
        a+=1;
        a=a+1; 

    are all equivalent in its functionality: the three increase by 1 the value of a.

    Its existence is because in the first C compilers the three previous expressions 
	produced different executable code according to which one was used. Nowadays this
	type of code optimization is generally done automatically by the compiler.

    A characteristic of this operator is that it can be used both as a prefix or
	as a suffix. That means it can be written before the variable identifier (++a) 
	or after (a++). Although in simple expressions like a++ or ++a they have exactly 
	the same meaning, in other operations in which the result of the increase or 
	decrease operation is evaluated as another expression they may have an important
	difference in their meaning: In case that the increase operator is used as a
	prefix (++a) the value is increased before the expression is evaluated and therefore 
	the increased value is considered in the expression; in case that it is used 
	as a suffix (a++) the value stored in a is increased after being evaluated and 
	therefore the value stored before the increase operation is evaluated in the 
	expression. Notice the difference:

        Example 1 	Example 2
        B=3;
        A=++B;
        // A is 4, B is 4 	B=3;
        A=B++;
        // A is 3, B is 4

    In Example 1, B is increased before its value is copied to A. While in Example 2,
	the value of B is copied to A and B is later increased.

Relational operators ( ==, !=, >, <, >=, <= )
    In order to evaluate a comparison between two expressions we can use the 
	Relational operators. As specified by the ANSI-C++ standard, the result of 
	a relational operation is a bool value that can only be true or false, 
	according to the result of the comparison.

    We may want to compare two expressions, for example, to know if they are equal
	or if one is greater than the other. Here is a list of the relational operators
	that can be performed in C++:

        ==	Equal
        !=	Different
        >	Greater than
        <	Less than
        >=	Greater or equal than
        <=	Less or equal than

    Here you have some examples:

        (7 == 5)	would return false.
        (5 > 4)	would return true.
        (3 != 2)	would return true.
        (6 >= 6)	would return true.
        (5 < 5)	would return false.

    of course, instead of using only numberic constants, we can use any valid 
	expression, including variables. Suppose that a=2, b=3 and c=6,

        (a == 5)	would return false.
        (a*b >= c)	would return true since (2*3 >= 6) is it.
        (b+4 > a*c)	would return false since (3+4 > 2*6) is it.
        ((b=2) == a)	would return true.

    Be aware. Operator = (one equal sign) is not the same as operator == 
	(two equal signs), the first is an assignation operator (assigns the right 
	side of the expression to the variable in the left) and the other (==) is a 
	relational operator of equality that compares whether both expressions in the 
	two sides of the operator are equal to each other. Thus, in the last expression 
	((b=2) == a), we first assigned the value 2 to b and then we compared it to a,
	that also stores value 2, so the result of the operation is true.

    In many compilers previous to the publication of the ANSI-C++ standard, as 
	well as in the C language, the relational operations did not return a bool 
	value true or false, rather they returned an int as result with a value of 0
	in order to represent "false" and a value different from 0 (generally 1) to 
	represent "true". For more information, or if your compiler does not support
	the bool type, consult the section bool type.

Logic operators ( !, &&, || ).
    Operator ! is equivalent to boolean operation NOT, it has only one operand, 
	located at its right, and the only thing that it does is to invert the value
	of it, producing false if its operand is true and true if its operand is 
	false. It is like saying that it returns the opposite result of evaluating 
	its operand. For example:

        !(5 == 5)	returns false because the expression at its right (5 == 5) 
		would be true.
        !(6 <= 4)	returns true because (6 <= 4) would be false.
        !true	returns false.
        !false	returns true.

    Logic operators && and || are used when evaluating two expressions to obtain 
	a single result. They correspond with boolean logic operations AND and 
	OR respectively. The result of them depends on the relation between its two operands:

        First
        Operand
        a	Second
        Operand
        b	result
        a && b	result
        a || b
        true	true	true	true
        true	false	false	true
        false	true	false	true
        false	false	false	false

    For example:

        ( (5 == 5) && (3 > 6) ) returns false ( true && false ).
        ( (5 == 5) || (3 > 6)) returns true ( true || false ).

Conditional operator ( ? ).
    The conditional operator evaluates an expression and returns a different 
	value according to the evaluated expression, depending on whether it is 
	true or false. Its format is:

        condition ? result1 : result2

    if condition is true the expression will return result1, if not it will 
	return result2.

        7==5 ? 4 : 3	  returns 3 since 7 is not equal to 5.
        7==5+2 ? 4 : 3	  returns 4 since 7 is equal to 5+2.
        5>3 ? a : b	  returns a, since 5 is greater than 3.
        a>b ? a : b	  returns the greater one, a or b.

  Conditional structure: if and else
It is used to execute an instruction or block of instructions only if a 
condition is fulfilled. Its form is:

    if (condition) statement

where condition is the expression that is being evaluated. If this condition
 is true, statement is executed. If it is false, statement is ignored 
 (not executed) and the program continues on the next instruction after 
 the conditional structure.

For example, the following code fragment prints out x is 100 only if the 
value stored in variable x is indeed 100:

    if (x == 100)
      cout << "x is 100";

If we want more than a single instruction to be executed in case that condition
 is true we can specify a block of instructions using curly brackets { }:

    if (x == 100)
     {
      cout << "x is ";
      cout << x;
     }

We can additionally specify what we want that happens if the condition is not 
fulfilled by using the keyword else. Its form used in conjunction with if is:

    if (condition) statement1 else statement2

For example:

    if (x == 100)
      cout << "x is 100";
    else
      cout << "x is not 100";

prints out on the screen x is 100 if indeed x is worth 100, but if it is not 
-and only if not- it prints out x is not 100.

The if + else structures can be concatenated with the intention of verifying a 
range of values. The following example shows its use telling if the present 
value stored in x is positive, negative or none of the previous, that is to say,
 equal to zero.

    if (x > 0)
      cout << "x is positive";
    else if (x < 0)
      cout << "x is negative";
    else
      cout << "x is 0";

Remember that in case we want more than a single instruction to be executed, 
we must group them in a block of instructions by using curly brackets { }.

  Repetitive structures or loops

Loops have as objective to repeat a statement a certain number of times or 
while a condition is fulfilled.

The while loop.
    Its format is:

        while (expression) statement

    and its function is simply to repeat statement while expression is true.

    For example, we are going to make a program to count down using a while loop:

  The do-while loop.
    Format:

        do statement while (condition);

    
Its functionality is exactly the same as the while loop except that condition 
in the do-while is evaluated after the execution of statement instead of before,
 granting at least one execution of statement even if condition is never fulfilled.


The for loop.
    Its format is:

        for (initialization; condition; increase) statement;

    and its main function is to repeat statement while condition remains true,
	like the while loop. But in addition, for provides places to specify an 
	initialization instruction and an increase instruction. So this loop is
	specially designed to perform a repetitive action with a counter.

    It works the following way:

        1, initialization is executed. Generally it is an initial value 
		setting for a counter varible. This is executed only once.
        2, condition is checked, if it is true the loop continues, 
		otherwise the loop finishes and statement is skipped.
        3, statement is executed. As usual, it can be either a single
		instruction or a block of instructions enclosed within curly brackets { }.
        4, finally, whatever is specified in the increase field is executed 
		and the loop gets back to step 2.


  The break instruction.
    Using break we can leave a loop even if the condition for its 
	end is not fulfilled. It can be used to end an infinite loop, 
	or to force it to end before its natural end. For example, we 
	are going to stop the count down before it naturally finishes (an engine failure maybe):

  The continue instruction.
    The continue instruction causes the program to skip the rest of 
	the loop in the present iteration as if the end of the statement 
	block would have been reached, causing it to jump to the following 
	iteration. 

Functions with no types. The use of void.
(most op2 triggers will be this)
If you remember the syntax of a function declaration:

    type name ( argument1, argument2 ...) statement

you will see that it is obligatory that this declaration begins with a
 type, that is the type of the data that will be returned by the function
 with the return instruction. But what if we want to return no value?

Imagine that we want to make a function just to show a message on the 
screen. We do not need it to return any value, moreover, we do not need 
it to receive any parameters. For these cases, the void type was devised 
in the C language.



 Taken From:http://www.cplusplus.com/doc/tutorial/


naming guidlines



  taken from: http://www.objectmentor.com/resources/articles/naming.htm
  
	Nouns and Verb Phrases

Classes and objects should have noun or noun phrase names.

There are some methods (commonly called "accessors") which calculate and/or return a value. These can and probably should have noun names. This way accessing a person's first name can read like:

        string x = person.name();

Other methods (sometimes called "manipulators", but not so commonly anymore) cause something to happen. These should have verb or verb-phrase names. This way, changing a name would read like:

        fred.changeNameTo("mike")

As a class designer, does this sound boringly unimportant? If so, then go write code that uses your classes. The best way to test an interface is to use it and look for ugly, contrived, or confusing text. This really helps. 
	  



Avoid Disinformation

Avoid words which already mean something else. For example, "hp", "aix", and "sco" would be horrible variable names because they are the names of Unix platforms or variants. Even if you are coding a hypotenuse and "hp" looks like a good abbreviation, it violates too many rules and also is disinformative.

Likewise don't refer to a grouping of accounts as an AccountList unless it's actually a list. A list means something to CS people. It denotes a certain type of data structure. If the container isn't a list, you've disinformed the programmer who has to maintain your code. AccountGroup or BunchOfAccounts would have been better.

The absolute worse example of this would be the use of lower-case L or uppercase o as variable names, especially in combination. The problem, of course is in code where such things as this occur:

    int a = l;
    if ( O = l )
        a = O1;
    else
        l = 0;

You think that I made this one up, right? Sorry. I've examined code this year (1997) where such things were abundant. It's a great technique for shrouding your code.

When I complained, one author told me that I should use a different font so that the differences were more obvious. I think that the problem could be more easily and finally corrected by search-and-replace than by publishing a requirement that all future readers to choose Font X.. 


Don't be too cute

If the names are too clever, they will be memorable only to people who share your sense of humor and remember the joke. Will the people coming after you really remember what HolyHandGrenade is supposed to do in your program? Sure, it's cute, but maybe in this case ListItemRemover might be a better name. I've seen Monty Python's The Holy Grail, but it may take me a while to realize what you are meaning to do.

I've seen other similar cutesy namings fail.

Given the choice, choose clarity over entertainment value. It's a good practice.
Most meanings have multiple words. Pick ONE

